#coding:utf-8
import requests
import demjson
import re
res = requests.get('http://104.168.159.24:5000/servers',timeout=10)
mayip = []
def t(ip):
    global mayip
    try:
        res = requests.get('http://' + ip + '/zgrabres.txt')
        print ip,res.text
        ips = re.findall('{"ip":"(.*?)","timestamp"',res.text,re.S)
        for ipx in ips:
            res = requests.get('http://'+ipx+"/aaa.bak")
            print ip,res.text,res.headers
            if res.status_code == 404:
                print ip,ipx,res.status_code,res.headers
                mayip.append(ipx)

    except Exception as e:
        print(ip,e)
servers = demjson.decode(res.text)
for server in servers:
    ip = server[1]
    t(ip)
# print '\n'.join(mayip)

for ip in mayip:
    res = requests.get('http://'+ip+'/assdsasad',headers={'Host':'admx.utm999.com'})
    if res.text.find('<title>404 - File or directory not found.</title>')>-1:
        print ip
